﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ServiceException.cs" company="Spenta Consulting">
//   (c) Copyright 2011
// </copyright>
// <summary>
//   Service exception (Exception wrapped for WCF transport)
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Spenta.StreetCare.MVC.Services.Data
{
    #region Using Directives

    using System;
    using System.Runtime.Serialization;

    #endregion

    /// <summary>
    /// Service exception (Exception wrapped for WCF transport)
    /// </summary>
    [DataContract]
    public class ServiceException
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceException"/> class.
        /// </summary>
        /// <param name="ex">The original exception.</param>
        public ServiceException(Exception ex)
        {
            if (ex != null)
            {
                this.Message = ex.Message;
                this.StackTrace = ex.StackTrace;
                this.MessageStackTrace = ex.ToString();
                this.HelpLink = ex.HelpLink;
                this.Source = ex.Source;
                this.InnerException = ex.InnerException != null ? new ServiceException(ex.InnerException) : null;
            }
        }

        /// <summary>
        /// Gets or sets the message.
        /// </summary>
        /// <value>The message.</value>
        [DataMember]
        public string Message { get; set; }

        /// <summary>
        /// Gets or sets the stack trace.
        /// </summary>
        /// <value>The stack trace.</value>
        [DataMember]
        public string StackTrace { get; set; }

        /// <summary>
        /// Gets or sets the message stack trace.
        /// </summary>
        /// <value>The message stack trace.</value>
        [DataMember]
        public string MessageStackTrace { get; set; }

        /// <summary>
        /// Gets or sets the source.
        /// </summary>
        /// <value>The source.</value>
        [DataMember]
        public string Source { get; set; }

        /// <summary>
        /// Gets or sets the help link.
        /// </summary>
        /// <value>The help link.</value>
        [DataMember]
        public string HelpLink { get; set; }

        /// <summary>
        /// Gets or sets the inner exception.
        /// </summary>
        /// <value>The inner exception.</value>
        [DataMember]
        public ServiceException InnerException { get; set; }
    }
}